/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.util.List;
import org.springframework.web.servlet.mvc.AbstractRestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.*;
import org.apache.log4j.xml.DOMConfigurator;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import model.Itinerario;
import model.Viaje;
import model.Lugar;
import service.GetUserCommand;
import service.ItinerarioService;
import service.ViajeService;
import service.LugarService;

public class ViajeController extends AbstractRestController {

    private ItinerarioService itinerarioService;
    private ViajeService viajeService;
    private LugarService lugarService;
    private static Logger loggers = null;

    public void setItinerarioService(ItinerarioService itinerarioService) {
        this.itinerarioService = itinerarioService;
    }

    public void setViajeService(ViajeService viajeService) {
        this.viajeService = viajeService;
    }

    public void setLugarService(LugarService lugarService) {
        this.lugarService = lugarService;
    }

    public ViajeController() {
        super();

        // Make sure to set which method this controller will support.
        this.setSupportedMethods(new String[]{METHOD_GET});
    }

    protected ModelAndView handle(HttpServletRequest request,
            HttpServletResponse response, Object commandObj, BindException errors)
            throws Exception {

        List iti;
        List via;
        Viaje viaje;
        Lugar lug;
        GetUserCommand command = (GetUserCommand) commandObj;

        viaje = viajeService.getViaje(Long.parseLong(command.getName()));
        // user=(Usuario) users.get(0);
        // via = viajeService.listdeMisViajes(user.getIdUsuario());

        iti = itinerarioService.getListaItinerario(Long.parseLong(command.getName()));
        System.out.print("itin " + iti.get(0));
        System.out.print(viaje.getLugar().getIdLugar());
        lug = lugarService.getLugar(viaje.getLugar().getIdLugar());
        System.out.print("itine222");
        System.out.print(lug.getNombre());
        System.out.println("hola aqui voy en VIAJE");
        ModelAndView mav = new ModelAndView();
        mav.addObject("itin", iti);
        mav.addObject("viaje", viaje);
        mav.addObject("lugar", lug);
        //mav.addObject("usuario",);
        return mav;

    }
}
